<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
  <title>项目追踪新增</title>
</head>
<style>
	.fieldset{
		margin-top: 5px;
		margin-bottom: 0px
	}
	
	.layui-legend{
		background-color:#5fb878;
		font-size:15px !important;
		width:140px;
	}
	.layui-form-item {
	    margin-bottom: 5px;
	    clear: both;
	    *zoom: 1;
	}
	.layui-form-label{width: 180px;}
</style>
<body>
<div class="layui-fluid">
    <div class="layui-card">
	    <div class="layui-tab-item layui-show">
	    	<div style="padding-top:15px;">&nbsp;</div>
			<form class="layui-form" id="addInfo_form">
				<fieldset class="layui-elem-field layui-field-title" style="margin-top: 16px;">
                 	<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;fontSize:100px;">项目基础信息></legend>
           		</fieldset>
				  <div style="margin-top:20px">
				  	<div class="layui-form-item">
						<div class="layui-inline">
					    	<label class="layui-form-label">项目名称</label>
				      		<div class="layui-input-inline">
					      		<select id="add_select_proId" name="pro"  lay-filter="add_select_proId" lay-verify="required" lay-search>
					      			<option value="">请选择-项目名称</option>
				      				<c:if test="${not empty allProName }">
				              			<c:forEach items="${allProName}" var="proNames">
				              				<option value="${proNames.proCode }_${proNames.id }_${proNames.hrStaffMktId}">${proNames.proName }</option>
					            		</c:forEach>
				              		</c:if>
				      			</select>
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">项目类型</label>
				      		<div class="layui-input-inline">
						        <input type="text" value="PPP项目" style="border:0px;" readonly="readonly" class="layui-input">
						        <input type="hidden" name="types" value="1">
						        <input type="hidden" id="proName" name="proName">
				      		</div>
					    </div>
					    <div class="layui-inline">
					   	 	<label class="layui-form-label">项目编号</label>
					   	 	<div class="layui-input-inline">
								<input name="proCode" id="proCode" style="border:0px;" readonly="readonly" class="layui-input" >
							</div>
						</div>
					</div>
					<div style="margin-top:12px"></div>					
				  	<div class="layui-form-item">
				  		<div class="layui-inline">
					      	<label class="layui-form-label">申请公司</label>
					      	<div class="layui-input-inline">
								<input type="hidden" name="hrOrgId" value="${bindOrgId}">
								<input type="text" value="${bindOrgName}" style="border:0px;width:220px" readonly="readonly" class="layui-input">
					      	</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">申请部门</label>
				      		<div class="layui-input-inline">
				      			<input type="hidden" name="hrDeptId" value="${bindDeptId}">
								<input type="text" value="${bindDeptName}" style="border:0px;" readonly="readonly" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">申请人</label>
				      		<div class="layui-input-inline">
				        		<input type="hidden" name="hrStaffApplyId" value="${SESSION_KEY_USER_DETAIL.hrStaffId }">
				        		<input type="text" name="staffName" value="${SESSION_KEY_USER_DETAIL.realName }" readonly="readonly" style="border:0px" autocomplete="off" class="layui-input">
				      		</div>
					    </div>
					</div>
					
					<div style="margin-top:12px"></div>	
			  		<div class="layui-form-item">
					    <div class="layui-inline">
					   	 	<label class="layui-form-label">一般公共预算收入（亿元）</label>
					   	 	<div class="layui-input-inline">
					   	 		<input id="pubIncome" name="pubIncome" style="border:0px;" readonly="readonly" class="layui-input" >
							</div>
						</div>
						<div class="layui-inline">
					   	 	<label class="layui-form-label">投资总额（万元）</label>
					   	 	<div class="layui-input-inline">
					   	 		<input  id="sumAmount" name="sumAmount" style="border:0px;" readonly="readonly" class="layui-input" >
							</div>
						</div>
						<div class="layui-inline">
					   	 	<label class="layui-form-label">建安工程费用（万元）</label>
					   	 	<div class="layui-input-inline">
					   	 		<input id="sumCae" name="sumCae" style="border:0px;" readonly="readonly" class="layui-input" >
							</div>
						</div>
						
						<div class="layui-inline">
					    	<label class="layui-form-label">项目重要等级</label>
				      		<div class="layui-input-inline">
					      		<select id="proLevel" name="proLevel" lay-filter="proLevel" lay-verify="required" lay-search>
					      			<option value="">请选择-项目重要等级</option>
				      				<option value="A">A类</option>
				      				<option value="B">B类</option>
				      				<option value="C">C类</option>
				      			</select>
				      		</div>
					    </div>
					    
				    </div>
				    
				 
				    <div style="margin-top:12px"></div>
			  		<div class="layui-form-item">
					    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 16px;">
                 			<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;fontSize:100px;">跟踪信息></legend>
           				</fieldset>
					    <div class="layui-inline">
					    <label class="layui-form-label">跟踪日期</label>
						   	<div class="layui-input-inline">
				             	<div class="layui-input-inline">
				               		<input type="text"  class="layui-input" id="trackDate" name="trackDate" readOnly placeholder="跟踪日期" lay-verify="required">
				             	</div>
		       				</div>
		       			</div>
		       			<div class="layui-inline">
		            	<label class="layui-form-label">项目阶段</label>
			            	<div class="layui-input-inline">
			              		<select name="proStage" lay-verify="required">
					              	<option value="">请选择-项目阶段</option>
					              	<option value="1">预立项通过</option>
					              	<option value="2">控股立项通过</option>
					              	<option value="3">资审通过</option>
					              	<option value="4">投标</option>
			              		</select>
			            	</div>
            			</div>
				    </div>
				    
				    <div style="margin-top:12px"></div>
			  		<div class="layui-form-item">
					    <div class="layui-inline">
					    	<label class="layui-form-label">当日推进情况</label>
				      		<div class="layui-input-inline">
					      		<textarea name="todayMemo" maxlength="500" placeholder="请输入当日推进情况" lay-verify="required" class="layui-textarea" style="width:899px;height:90px;"></textarea>
				      		</div>
					    </div>
				    </div>
				    <div style="margin-top:12px"></div>
				  	<div class="layui-form-item">
					    <div class="layui-inline">
					    	<label class="layui-form-label">次日推进计划</label>
				      		<div class="layui-input-inline">
					      		<textarea name="tomorrowPlan" maxlength="500" placeholder="请输入次日推进计划" lay-verify="required" class="layui-textarea" style="width:899px;height:90px;"></textarea>
				      		</div>
					    </div>
				    </div>
				  </div> 
				  <div class="layui-form-item" style="position: fixed ! important; right: 30px; bottom:45%;z-index:10000;">
						<div class="layui-input-block">
				      		<button class="layui-btn layui-bg-blue layui-btn-normal layui-btn-lg  layui-btn-radius" type="button" lay-submit lay-filter="addInfo_form_submit" id="addInfo_form_submit">
				      		<i class="layui-icon layui-icon-ok layuiadmin-button-btn"></i>
				      		提交
				      		</button>
				      	</div>
			      </div>			
			</form>
  		</div>
	</div>
</div>
  <script>

  layui.config({
    base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'set', 'upload', 'element', 'laydate'], function(){
    var $ = layui.$
    ,form = layui.form
    ,element = layui.element
    ,laydate = layui.laydate
    ,upload = layui.upload;
    
 	// 正则校验
	form.verify({
		//验证汉字
	    CHS:[
	    	/^[\u0391-\uFFE5]+$/
	    	,'只能输入汉字'
	  	],
	  	//大于0的正整数
	  	intNumber:[
			/^[1-9]\d*$/
			,'请输入正确的数字'
	  	],
	  	//数字只能有两位小数
	  	floatNumber:[
			/^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			,'请输入正确的数字'
	  	],
	  	//数字大于等于0，并只能有两位小数
	  	floatAmount:[
			/^([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			//var pattern=/^((\d+\.\d*[1-9]\d{1})|(\d*[1-9]\d*\.\d{2}))$/; 
			,'请输入正确的数字'
	  	]
	});
 	
	//跟踪日期
    laydate.render({
      elem: '#trackDate'
    });
	
	
	//项目名称select监听
    form.on('select(add_select_proId)', function(data){
    	var codeAndId = data.value;
    	$('#proCode').val('');  //把id为proCode的标签的值改为' '
    	$("#proName").val('');
    	$('#pubIncome').val('');
    	$('#sumAmount').val('');
    	$('#sumCae').val('');
    	if(codeAndId == null || codeAndId == ''){
    		layer.msg('请选择项目名称~',{icon: 0});
    		return;
    	}else{
    		var proName = $("#add_select_proId").find("option:selected").text().trim();
    		$("#proName").val(proName);
    		$('#proCode').val(codeAndId.split("_")[0]);  //把id为proCode的标签的值改为' '
    	}
    	getProPlotProId(codeAndId);   	
    }); 
   	//监听提交
  	form.on('submit(addInfo_form_submit)', function(data){
  		$("#addInfo_form_submit").removeAttr("lay-submit").removeClass("layui-bg-blue").addClass("layui-btn-disabled");
  		layer.load();
       	//提交 Ajax 成功后，静态更新表格中的数据
       	$.ajax({
           	type : 'post',
			url : basePath + '/proTrack/save',
           	data: $('#addInfo_form').serialize(),
			success:function(result){
				if(result.success){
					layer.closeAll('loading'); //关闭loading
					layer.msg('提交成功~',{icon: 1});
					//两秒后关闭当前页面
					setTimeout(function(){
						/**
						 * 查找父菜单，并刷新
						 */
						var topDoc = $(window.top.document);
						var path = basePath + '/proTrack/list';
						// 获取页面名称
						var name = topDoc.find(".layui-nav-item [lay-href^='" + path + "']").text();
						if(name == '' || name == null){
							name = '项目追踪';
						}
						window.parent.layui.index.openTabsPage(path, name);
						var iframe = window.parent.layui.admin.tabsBody(window.parent.layui.admin.tabsPage.index).find(".layadmin-iframe");
						iframe[0].contentWindow.location.reload(true);
						
						/**
						 * 关闭当前页
						 */
						var currPath = basePath + '/proTrack/add';
						var layid = topDoc.find("li[lay-id^='" + currPath + "']").attr('lay-id');
						window.parent.layui.element.tabDelete('layadmin-layout-tabs', layid);//关闭当前页
				        }, 2000);
				}else{
					layer.closeAll('loading'); //关闭loading
  					$("#addInfo_form_submit").removeClass("layui-btn-disabled").addClass("layui-bg-blue").attr("lay-submit","");
					layer.msg(result.msg,{icon: 7});
			  	}
			}
       	});
   	});  
 	// data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  	
  });
	  function getProPlotProId(codeAndId){
		var $ = layui.$
	  	,form = layui.form
			$.ajax({
				type : "POST", //提交方式  
				url : "${ctx}/proTrack/getPubIncome",//带出项目编号
				data : {
					"codeAndId" :codeAndId
				},//数据，这里使用的是Json格式进行传输  
				success : function(result) {//返回数据根据结果进行相应的处理 
					if(result.flag==true){
						//带出一般公共预算收入
						if(result.pubIncome != null && result.pubIncome != ''){
							$('#pubIncome').val(result.pubIncome);
						}else{
							$('#pubIncome').val('');
						}
						//带出投资总额和建安工程费用
						if(result.sumAmount != null && result.sumAmount != ''){
							$('#sumAmount').val(result.sumAmount);
						}else{
							$('#sumAmount').val('');
						}
						if(result.sumCae != null && result.sumCae != ''){
							$('#sumCae').val(result.sumCae);
						}else{
							$('#sumCae').val('');
						}
					}else{
						layer.msg('未查到该项目的记录信息~',{icon: 0});
					}
				} 
			});
	  }
	  
	//根据下拉选择不同显示不同的div
	  layui.use(['form','layer','jquery'], function(){
	      var $ = layui.jquery,
	          layer = layui.layer,
	          form = layui.form; 
	      form.on('select(noteType)', function(data){
	          
	      })
	  });
  </script>
</body>
</html>